package com.xsmart.goods.services.wx;

import com.baomidou.mybatisplus.plugins.Page;
import com.xsmart.common.constant.ResultConstant;
import com.xsmart.common.entity.RequestBean;
import com.xsmart.common.entity.ResponseBean;
import com.xsmart.goods.dao.GoodsCategoryDao;
import com.xsmart.goods.dao.wx.WxGoodsCategoryDao;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 微信接口服务
 * @author guojd
 * @version V1.0.0
 */

@Service
public class WxGoodsCategoryService {
    @Autowired
    WxGoodsCategoryDao goodsCategoryDao;

    /**
     * 查询商品类型
     *
     * @param requestBean 请求对象
     * @return 返回对象
     */
    public ResponseBean queryGoodsCategoryRoot(RequestBean requestBean) {
        ResponseBean responseBean = requestBean.getResponseBean();
        List<Map<String, Object>> list=goodsCategoryDao.queryGoodsCategory(null);
        List<Map<String, Object>> catList;
        if(list.size()>0){
            catList=goodsCategoryDao.queryGoodsCategory(MapUtils.getLong(list.get(0),"id"));
        }else{
            catList=new ArrayList<>();
        }

        responseBean.addResultItem("list", list);
        responseBean.addResultItem("catList", catList);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }

    /**
     * 查询商品类型
     *
     * @param requestBean 请求对象
     * @return 返回对象
     */
    public ResponseBean queryGoodsCategory(RequestBean requestBean) {
        long id=requestBean.getRequestParamLong("cat_id");
        ResponseBean responseBean = requestBean.getResponseBean();
        List<Map<String, Object>> catList=goodsCategoryDao.queryGoodsCategory(id);
        responseBean.addResultItem("catList", catList);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }
}
